package com.itshen.one.producer;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: stephen.shen
 * @create: 2018-12-13 9:31
 */
@Component
public class Producer {

    public final static String TEST_KEY = "test.key";

    @Autowired
    AmqpTemplate amqpTemplate;

    public void sendMessage(String message) {
        // 使用默认的exchange
        amqpTemplate.convertAndSend(TEST_KEY, message, m -> {
            // 设置消息持久化
            m.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
            return m;
        });
    }
}
